package dom;

import bean.user;
import cont.contr;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class logdom extends user {
    public static String login(String id, String mm) throws SQLException {
        PreparedStatement pstmt;
        String name = null;
        try {

            Connection conn = contr.getConn();
            String sql = "select name from user where userid= ? and password=?  ";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, id);
            pstmt.setString(2, mm);
            pstmt.execute();
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                name = rs.getString(1);
                System.out.println("用户查询");
                rs.close();
                System.out.print("查询已完成");
                pstmt.close();
                System.out.print("关闭查询");
                conn.close();
                System.out.print("关闭数据库连接");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return name;
    }

    public static boolean login2(String name) throws SQLException, ClassNotFoundException {

        PreparedStatement pstmt = null;
        boolean flag1 = false;
        Connection conn = contr.getConn();
        String sql2 = "select * from admin where name= ? ";
        pstmt = conn.prepareStatement(sql2);
        pstmt.setString(1, name);
        pstmt.execute();
        ResultSet r = pstmt.executeQuery();
        if (r.next()) {
            System.out.println("用户类型查询");
            flag1 = true;
            r.close();
            System.out.println("查询已完成");
            pstmt.close();
            System.out.println("关闭查询");
            conn.close();
            System.out.println("关闭数据库连接");

        }
        return flag1;
    }
}